package com.simplegovern.authority.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.simplegovern.authority.SysRoleAction;
import com.simplegovern.authority.dao.RoleActionDAO;

public class RoleActionService {

	@Autowired
	private RoleActionDAO roleActionDAO;
	
	public List<SysRoleAction> getRoleActionList(Long roleId){
		return roleActionDAO.getRoleActionList(roleId);
	}
	
	public void remove(Long roleId){
		List<SysRoleAction> sras = getRoleActionList(roleId);
		for (SysRoleAction sysRoleAction : sras) {
			roleActionDAO.delete(sysRoleAction.getId());
		}
	}
	
	public void add(Long[] actionIds, Long roleId){
		for (Long actionId : actionIds) {
			SysRoleAction sra = new SysRoleAction();
			sra.setActionId(actionId);
			sra.setRoleId(roleId);
			roleActionDAO.save(sra);
		}
	}
}
